package com.ruoyi.web.controller.aop;

import com.ruoyi.manage.domain.Order;
import com.ruoyi.manage.service.ISendMessageService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @Author: wwy
 * @Date: 2021/3/4 16:19
 */
@Aspect
@Component
public class OrderAop {
    @Autowired
    private ISendMessageService sendMessageService;

    @Pointcut("execution(* com.ruoyi.web.controller.manage.AppOrderController.addOrder(..))")
    public void pointcut() {
    }


    @AfterReturning(value = "pointcut()",returning = "returnObject")
    public void afterReturning(JoinPoint joinPoint, Object returnObject) {
        Object[] args = joinPoint.getArgs();
        Order order = null;
        for (Object arg : args) {
            if( arg instanceof Order){
                order = (Order) arg;
                break;
            }
        }
        //获取违法类型
        Integer illegalType = order.getIllegalType();
        String jurisdictionName = order.getJurisdiction();
        //发送语音与短信
        sendMessageService.sendMessage(illegalType,jurisdictionName);
    }


}
